package com.itheima.array;

public class BinarySearch {

    public static void main(String[] args) {
        //定义数组
        int[] arr={11,22,33,44,55,66,77,88};
        //调用查找方法
        int index = getIndex(arr, 11);
        System.out.println(index);
    }


    //定义方法
    //参数  数组  int[] arr  元素 int number
    // 返回值 int
    public  static int getIndex(int[] arr ,int number){
       int begin=0;
       int end=arr.length-1;

        while(begin<=end){
            int mid=(begin+end)/2;//>>1  >>>1
            if(number<arr[mid]){
                end=mid-1;
            }else if(number>arr[mid]){
                begin=mid+1;
            }else{
                return mid;
            }
        }

        return -1;
    }


}
